package messages;

/**
 * 
 * 
 * @author Ian Doerr
 */
public class KillOrderMessage extends BaseMessage {

	private static final String CORRECT_ACTIVATION_KEY = "The time has come. Execute Order 66.";
	private boolean isOrder = false;
	
	public KillOrderMessage(byte[] data) {
		super(data);
		
		CString activationKey = new CString(data, 1);
		String key = activationKey.toString();
		
		isOrder = CORRECT_ACTIVATION_KEY.equals(key);
	}

	public KillOrderMessage(){
		super(null);
		isOrder = true;
	}
	
	public boolean isKillOrder(){
		return isOrder;
	}
	
	@Override
	public byte[] toByteArray() {
        
		if (!isOrder)
		{
			return null;
		}
        
        ByteList byteOutput = new ByteList();
        byteOutput.addByte(getMessageType().getIdentifier());
        new CString(CORRECT_ACTIVATION_KEY).appendToByteList(byteOutput);
        
		return byteOutput.toByteArray();
	}

	@Override
	public int getMessageSize() {
		return 2 + CORRECT_ACTIVATION_KEY.length();
	}

	@Override
	public MessageType getMessageType() {
		return MessageType.KillOrderMessage;
	}

}
